package com.ext.aic.components;

import android.annotation.SuppressLint;
import android.content.Context;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ext.aic.R;
import com.ext.aic.adapter.MenuAdapter;
import com.ext.aic.beans.MenuItem;
import com.eyinfo.android_pure_utils.events.Action1;
import com.eyinfo.android_pure_utils.utils.PixelUtils;
import com.lxj.xpopup.core.BottomPopupView;

import java.util.List;

import lombok.Setter;

public class MenuBottomPopup extends BottomPopupView {

    private List<MenuItem> items;
    @Setter
    private Action1<MenuItem> itemClickCall;

    public MenuBottomPopup(Context context, List<MenuItem> items) {
        super(context);
        this.items = items;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.menu_popup_view;
    }

    @Override
    protected int getMaxHeight() {
        return PixelUtils.dip2px(getContext(), 200);
    }

    @SuppressLint("NotifyDataSetChanged")
    @Override
    protected void onCreate() {
        RecyclerView recyclerView = findViewById(R.id.menu_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        MenuAdapter menuAdapter = new MenuAdapter(this.items);
        menuAdapter.setItemClickCall((item) -> {
            if (itemClickCall != null) {
                itemClickCall.call(item);
            }
            dismiss();
        });
        recyclerView.setAdapter(menuAdapter);
        menuAdapter.notifyDataSetChanged();
    }
}
